package queue.offical;

import java.util.LinkedList;
import java.util.Queue;

/**
 * @BelongsProject: leetcode
 * @BelongsPackage: queue
 * @Author: Administrator
 * @CreateTime: 2018-12-09 12:03
 * @Description: leetcode 225 用队列实现栈
 */
public class QueueToStack {
    private Queue<Integer> myQueue;

    public QueueToStack() {
        myQueue=new LinkedList<>();
    }

    /** Push element x onto stack. */
    public void push(int x) {
        int n= myQueue.size();
        Queue<Integer> tempQueue= new LinkedList();
        for(int i= 0; i<n; i++){
            tempQueue.add(myQueue.poll());
        }
        myQueue.add(x);
        for(int i= 0; i<n; i++){
            myQueue.add(tempQueue.poll());
        }
    }

    /** Removes the element on top of the stack and returns that element. */
    public int pop() {
        return myQueue.poll();
    }

    /** Get the top element. */
    public int top() {
        return myQueue.peek();
    }

    /** Returns whether the stack is empty. */
    public boolean empty() {
        return myQueue.isEmpty();
    }
}
